package com.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.mapper.ClassroomMapper;
import com.demo.pojo.entity.Classroom;
import com.demo.pojo.dto.ClassroomListDTO;
import com.demo.service.ClassroomService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 教室服务实现类
 */
@Service
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom> implements ClassroomService {
    
    @Override
    public List<ClassroomListDTO> getClassroomList() {
        List<Classroom> classrooms = list();
        return classrooms.stream()
                .map(classroom -> {
                    ClassroomListDTO dto = new ClassroomListDTO();
                    BeanUtils.copyProperties(classroom, dto);
                    return dto;
                })
                .collect(Collectors.toList());
    }
    
    @Override
    public List<Classroom> getAvailableClassroomsByType(String classroomType) {
        QueryWrapper<Classroom> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("classroom_type", classroomType)
                   .eq("status", 1);
        return list(queryWrapper);
    }
    
    @Override
    public boolean isClassroomAvailable(Long classroomId, Long timeSlotId) {
        // 这里需要检查该教室在指定时间段是否已被占用
        // 实际实现中需要查询schedule表
        return true; // 简化实现
    }
}
























